using Newtonsoft.Json;
using TripleA.Core.Interfaces;
using TripleA.Core.Interfaces.Entities;

namespace TripleA.Core.Extensions
{
    public abstract class StepBase<T> :IPipelineStep<T>
    {
        public virtual void PreValidate(T context)
        {
            
        }

        public abstract void Execute(T context);

        public virtual void PostValidate(T context)
        {
            
        }

        public StepResult<T> GenerateResult(int index)
        {
            return new StepResult<T>(index)
                       {
                           Name = GetType().Name
                       };
        }

        public virtual PipelineStepSnapshot Dehydrate()
        {
            return new PipelineStepSnapshot
                       {
                           Target = GetType(),
                           Snapshot = GetSnapshot()
                       };
        }

        protected virtual string GetSnapshot()
        {
            return JsonConvert.SerializeObject(this);
        }
    }
}